package cn.edu.scau.cmi.mazhuanglong.comprehensive;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.ScrollPane;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.NumberFormat;
import java.awt.*;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.JTableHeader;

public class MyTableModel2 extends AbstractTableModel {
	String[] a = new String[] { "\u5B66\u53F7", "\u59D3\u540D", "\u5E73\u65F6\u6210\u7EE9", "\u671F\u672B\u6210\u7EE9",
			"\u603B\u8BC4" };
	public static Object[][] obj;

	public MyTableModel2() {
		int n = 2017270201;
		obj = new Object[30][5];
		for (int i = 0; i < 30; i++) {
			for (int j = 0; j < 5; j++) {
				if (j == 0)
					obj[i][j] = n + i;
				else if (j == 1)
					obj[i][j] = "小红";
				else if (j == 2)
					obj[i][j] = 70 + i;
				else if (j == 3)
					obj[i][j] = 60 + i;
				else {
					double totalScore = (double) new Double(getValueAt(i, 2).toString()) / 2
							+ (double) new Double(getValueAt(i, 3).toString()) / 2;
					if (totalScore < 0)
						totalScore = 0;
					NumberFormat nf = NumberFormat.getNumberInstance();
					nf.setMaximumFractionDigits(2);
					obj[i][j] = nf.format(totalScore);
				}

			}
		}
	}

	public String getColumnName(int column) {
		return a[column].toString();
	}

	@Override
	public int getColumnCount() {// 获取列数
		// TODO Auto-generated method stub
		return a.length;
	}

	@Override
	public int getRowCount() {// 获取行数
		// TODO Auto-generated method stub
		return obj.length;
	}

	@Override
	public Object getValueAt(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return obj[arg0][arg1];
	}
}
